package 牛客网_N.查找_递归_排序_贪心.矩阵元素查找;

public class Main {
	public static void main(String[] args){
		int target = 6;
		int[][] A = new int[][]{{1,3,5},{2,4,6}}; 
		System.out.println(findElement(A, A.length, A[0].length, target)[0]);
		System.out.println(findElement(A, A.length, A[0].length, target)[1]);
	}

	public static int[] findElement(int[][] mat, int n, int m, int x) {
		int row = 0;
		int col = m-1;
		int[] res = new int[2];
		while(row <= n-1 && col >= 0){
				if(mat[row][col] > x) col--;
				else if(mat[row][col] < x) row++;
				else {
					res[0] = row;
					res[1] = col;
					return res;
				};
		}
		return res;
	}

}
